#!/bin/bash -ex

SCRIPT_DIR="$(realpath "$(dirname "${0}")")"
ASPT_DIR="$(realpath "$(dirname "${1}")")"
ASPT_FILE_NAME="$(basename "$(realpath "${1}")")"

# LOCAL_BUILD_PANDA="/home/aleks/build_dirs/panda_sdks_buids/sdk_host_release/linux_host_tools/"
LOCAL_BUILD_PANDA="/home/aleks/repos/idlize/external/incremental/tools/panda/node_modules/@panda/sdk/linux_host_tools/"
ASPT_CONVERTER="${LOCAL_BUILD_PANDA}/bin/aspt_converter"
FLAMEGRAPH="/home/aleks/repos/FlameGraph/flamegraph.pl"

SUMMARY_TOOL="${SCRIPT_DIR}/../build/bin/find_top_sample"

${ASPT_CONVERTER} --input="${ASPT_DIR}/${ASPT_FILE_NAME}" --output="${ASPT_DIR}/${ASPT_FILE_NAME}.csv"
${FLAMEGRAPH} "${ASPT_DIR}/${ASPT_FILE_NAME}.csv" > "${ASPT_DIR}/${ASPT_FILE_NAME}.html"
${FLAMEGRAPH} --flamechart "${ASPT_DIR}/${ASPT_FILE_NAME}.csv" > "${ASPT_DIR}/${ASPT_FILE_NAME}_flamechart.html"
${SUMMARY_TOOL} --panda "${ASPT_DIR}/${ASPT_FILE_NAME}.csv"
